// 提示
const showToast = (text,position,duration,icon)=>{
  try{
    // 默认值
    if(!position){   // 如果不传位置默认为居中
      position = "center"
    }else{
      if(position == 0)position = "top"
      if(position == 1)position = "center"
      if(position == 2)position = "bottom"
    }
    if(!icon)icon = "none"  // 如果不传图标默认为空
    if(!duration)duration = 2000   // 如果不传时间默认为2000ms
    wx.showToast({
      title:text,
      icon:icon,
      position:position,
      duration:duration
    })
  }catch(e){
    console.log(e)
  }
}

// 计算金额
const money = (A,B,method,digit)=>{
  let result = null
  if(!digit)digit = 2 // 如果不规定保留几位小数默认保留2位
  switch (method){
    case '+':
      return result = parseFloat(A+B).toFixed(digit)
      break;
    case '-':
      return result = parseFloat(A-B).toFixed(digit)
      break;
    case '*':
      return result = parseFloat(A*B).toFixed(digit)
      break;
    case '/':
      return result = parseFloat(A/B).toFixed(digit)
      break;
    default:
      return "计算错误"
      break;
  }
}
module.exports = {
  showToast,
  money:money
}

